# Makefile for inetutils
#
# Copyright (C) 1995, 1996 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

SHELL = /bin/sh

srcdir = @srcdir@
top_srcdir = @top_srcdir@
include config.make

SUBDIRS = @SUBDIRS@
SERVERS = @COMMON@ @SERVERS@
CLIENTS = @COMMON@ @CLIENTS@
BOTH = @COMMON@ @SERVERS_OR_CLIENTS@

DISTFILES = ChangeLog INSTALL NEWS README config.guess \
	config.make.in config.sub configure configure.in install-sh \
	mkinstalldirs rules.make
MAINTCLEAN = configure

DISTCLEAN = include config.make config.status config.log Makefile

all:	   $(addsuffix -all,$(BOTH))
install:   install-both
uninstall: uninstall-both
clients:   $(addsuffix -all,$(CLIENTS))
servers:   $(addsuffix -all,$(SERVERS))

clean: clean-subdirs
distclean: distclean-subdirs
	$(RM) -rf $(DISTCLEAN)
maintainer-clean: maintainer-clean-subdirs
	$(RM) -rf $(DISTCLEAN) $(MAINTCLEAN)

%-clients: $(addprefix %-,$(CLIENTS))	;
%-servers: $(addprefix %-,$(SERVERS))	;
%-both:    $(addprefix %-,$(BOTH))	;
%-subdirs: $(addprefix %-,$(SUBDIRS))	;

$(addsuffix -all,$(SUBDIRS))       : %-all       : ; $(MAKE) -C $* all
$(addprefix install-,$(SUBDIRS))   : install-%   : ; $(MAKE) -C $* install
$(addprefix uninstall-,$(SUBDIRS)) : uninstall-% : ; $(MAKE) -C $* uninstall
$(addprefix clean-,$(SUBDIRS))     : clean-%     : ; $(MAKE) -C $* clean
$(addprefix distclean-,$(SUBDIRS)) : distclean-% : ; $(MAKE) -C $* distclean
$(addprefix maintainer-clean-,$(SUBDIRS)) : maintainer-clean-% : ; $(MAKE) -C $* maintainer-clean

$(addprefix dist-,$(SUBDIRS))      : dist-%      :
	$(MAKE) -C $* dist DISTDIR=../$(DISTDIR)/$*

dist: $(DISTFILES) dist-prepare dist-subdirs dist-package

DISTDIR = `cat distname`
distname: libinetutils/version.c
	echo inetutils-`sed -e '/inetutils_version/!d' \
	    -e 's/[^0-9.]*\([0-9.a-z]*\).*/\1/' -e q $<` > $@-tmp
	mv $@-tmp $@
dist-prepare: distname
	rm -rf $(DISTDIR)
	mkdir $(DISTDIR)
	@for subdir in $(SUBDIRS); do \
	  echo mkdir $(DISTDIR)/$$subdir; mkdir $(DISTDIR)/$$subdir || exit 1; \
	done
	$(LINK_DISTFILES)
dist-package: distname
	tar --gzip -chvf $(DISTDIR).tar.gz $(DISTDIR)
	rm -rf $(DISTDIR) distname

.PHONY: clients servers both subdirs
